/**
 * @param {number[]} height
 * @return {number}
 */
// 超时
// var maxArea = function (height) {
//   let left = 0
//   let maxArea = 0
//   const n = height.length
//   height.forEach((item, index) => {
//     for (let i = 1; i < n; i++) {
//       let max = Math.min(item, height[i]) * (i - index)
//       if (max > maxArea) maxArea = max
//     }
//   })
//   console.log(maxArea);
//   return maxArea
// };

var maxArea = function (height) {
  let left = 0;
  let right = height.length - 1;
  let ans = 0
  while (left < right) {
    let area = Math.min(height[left], height[right]) * (right - left)
    ans = Math.max(area, ans)
    if (height[left] < height[right]) {
      left++;
    } else {
      right--;
    }
  }
  return ans
}
let arr = [1, 1]
maxArea(arr)